package liy.demo.wikiproject.controller;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import liy.demo.wikiproject.req.EbookQueryReq;
import liy.demo.wikiproject.req.EbookSaveReq;
import liy.demo.wikiproject.resp.CommonResp;
import liy.demo.wikiproject.resp.EbookResp;
import liy.demo.wikiproject.resp.PageResp;
import liy.demo.wikiproject.service.EBookService;
import liy.demo.wikiproject.util.SnowFlake;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ebook")
public class EbookController {


    @Resource
    private EBookService ebookService;
    @RequestMapping("list")
    public CommonResp<PageResp<EbookResp>> list( @Valid EbookQueryReq req) {
        CommonResp<PageResp<EbookResp>> resp = new CommonResp<>();
        PageResp<EbookResp> list = ebookService.list(req);
        resp.setContent(list);
        return resp;
    }
    @PostMapping("save")
    public CommonResp save(@RequestBody EbookSaveReq req) {
        CommonResp<EbookSaveReq>resp = new CommonResp<>();
        ebookService.save(req);
        return resp;
    }

    @RequestMapping("list/category")
    public CommonResp<PageResp<EbookResp>> listCategory(EbookQueryReq req) {
        CommonResp<PageResp<EbookResp>> resp = new CommonResp<>();
        PageResp<EbookResp> list = ebookService.listByCategory(req);
        resp.setContent(list);
        return resp;
    }

    @RequestMapping("delete/{id}")
    public CommonResp<String> deleteById(EbookQueryReq req) {
        CommonResp<String> delete = ebookService.delete(req);
        return delete;
    }

}
